package cn.wolfcode.rbac.web.controller;

import cn.wolfcode.rbac.domain.Customer;
import cn.wolfcode.rbac.domain.Customertracehistory;
import cn.wolfcode.rbac.query.QueryObject;
import cn.wolfcode.rbac.service.ICustomertracehistoryService;
import cn.wolfcode.rbac.service.ISystemDictionaryItemService;
import cn.wolfcode.rbac.util.JsonResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/customerTraceHistory")
public class CustomertracehistoryController {
    @Autowired
    private ICustomertracehistoryService customertracehistoryService;
    @Autowired
    private ISystemDictionaryItemService systemDictionaryItemService;
    //跟进历史管理列表
    @RequestMapping("/list")
    public String list(@ModelAttribute("qo") QueryObject qo, Model model){
        PageInfo pageInfo = customertracehistoryService.selectAll(qo);
        model.addAttribute("traceTypes",this.systemDictionaryItemService.selectMode());
        model.addAttribute("result",pageInfo);
        return "customerTraceHistory/list";
    }

    //向跟进历史插入一条数据
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public JsonResult saveOrUpdate(Customertracehistory customertracehistory){
        try{
            this.customertracehistoryService.insert(customertracehistory);
            return new JsonResult("操作成功", true);
        }catch (Exception e){
            e.printStackTrace();
            return new JsonResult("操作失败", false);
        }
    }

    //修改跟进历史的数据
    @RequestMapping("/update")
    @ResponseBody
    public JsonResult update(Customertracehistory customertracehistory){
        try{
           System.out.println(customertracehistory.getTrace_details());
           this.customertracehistoryService.update(customertracehistory);
            return new JsonResult("操作成功", true);
        }catch (Exception e){
            e.printStackTrace();
            return new JsonResult("操作失败", false);
        }
    }
}
